package org.tang.springcloudvv.util;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 在日志中不打印敏感字段
 */
public class MapUtils {

    private static List<String> listFilter = new ArrayList<String>();
    static
    {
        //需要过滤掉的字段
        listFilter.add("password");
        listFilter.add("token");
        listFilter.add("key");
        listFilter.add("ticket");
        listFilter.add("accessToken");
        listFilter.add("accesstoken");
    }
    /*
    获取过滤后的参数map
     */
    public static Map<String, String[]> getMapFilter(Map<String, String[]> map)
    {
        Map<String, String[]> map_ = new HashMap<>();
        map_.putAll(map);

        //过滤掉
        for (String key:listFilter)
        {
            if (map_.containsKey(key))
            {
                map_.put(key,new String[]{"过滤敏感字段"});
            }
        }

        return map_;
    }
}
